<template>
	<div class="post_list_my_manage_buy">
		<!-- 自定义头部 -->
		<BhTitle :titleText="titleText"></BhTitle>
		<view class="list" v-if="records.length > 0">
			<view class="li" v-for="(item, index) in records" :key="index" @click="checkDetail(item)">
				<view class="tag"></view>
				<view class="f32 fw600">求租{{ item.area }}的店铺</view>
				<view class="c9">
					<text>{{ item.createTimeDesc }}</text>|<text>{{ item.viewNumber }}次浏览</text>
				</view>
				<view class="line"></view>
				<view class="f28"><text>面积要求:</text>{{ item.askForAcreage }}</view>
				<view class="f28"><text>租金范围:</text>{{ item.askForupperRent }}</view>
				<view class="f28"><text>区域要求:</text>{{ item.street }}</view>
				<view class="f28"><text>商铺类型:</text>{{ item.industryName }}</view>
				<view class="mb0 f28"><text>是否接受转让费:</text>{{ item.transferFeeDiscuss == 1 ? '是' : '否' }}</view>
				<view class="cccline"></view>
				<view class="operate">
					<view class="" @click.stop="del(item)">删除</view>
					<view class="" @click.stop="edit(item)">修改</view>
				</view>
			</view>
		</view>
		<view v-else style="margin-top: 20vh;">
			<bh-no-more></bh-no-more>
		</view>
		<showCustomModal></showCustomModal>

		<view class="bh-round-btn" @click="toPost('/PostPage/post_add_buy/post_add_buy')">新建选址需求</view>
		<view class="" style="height: 200rpx;"></view>
	</div>
</template>

<script>
import { Api } from '../../api/api';
import bhNoMore from '../../components/custom_views/bh-no-more.vue';
import check_utils from '../../components/custom_views/check_utils';
import { CustomDict } from '../../components/custom_views/custom_dict';
import {
	Dict
} from '../../components/custom_views/dict';
export default {
	mixins: [],
	components: {
		bhNoMore,

	},
	data() {
		return {
			titleText: '找铺发布',
			records: [],
			pickerList: [],
			CustomDict,
			Dict,
		}
	},
	filters: {},

	watch: {},

	// 页面周期函数--监听页面加载
	onLoad() {
		this.initList()

	},

	onPullDownRefresh(){
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 500);
	},
	methods: {
		initList() {
			let that = this
			function upK(num) {
				return num >= 10000 ? num / 10000 + '万' : num + '元'
			}
			Api.MyApi.listOfMy(that, (res) => {
				if (res.data.records) {
					//页面弄filters不生效 就这么循环加进去了 ㎡
					for (var i = 0; i < res.data.records.length; i++) {
						res.data.records[i].industryName = CustomDict.getDictName(res.data.records[i].industryId, Dict.IndustryTypeEnum)
						if (res.data.records[i].lowerAcreage == 500) {
							res.data.records[i].askForAcreage = '500㎡以上'
						} else if (res.data.records[i].upperAcreage >= 10000) {
							res.data.records[i].askForAcreage = '不限'
						} else {
							res.data.records[i].askForAcreage = res.data.records[i].lowerAcreage + '-' + res.data.records[i].upperAcreage + '㎡'
						}
						if (res.data.records[i].lowerRent == 50000) {
							res.data.records[i].askForupperRent = '5万元以上'
						} else if (res.data.records[i].upperRent >= 1000000) {
							res.data.records[i].askForupperRent = '不限'
						} else {
							res.data.records[i].askForupperRent = upK(res.data.records[i].lowerRent) + '-' + upK(res.data.records[i].upperRent)
						}

					}
					this.records = res.data.records.filter((item) => { return item.postType == 120101 })
				}


			})
		},

		//跳转详情---后续加上data参数
		checkDetail(item) {
			let detailJson = encodeURIComponent(JSON.stringify(item))
			uni.navigateTo({
				url: 'PostPage/post_detail_buy/post_detail_buy?detailJson=' + detailJson + '&postId=' + item.id
			})
		},
		toPost(pageUrl) {
			uni.navigateTo({
				url: pageUrl
			})
		},
		edit(item) {
			uni.navigateTo({
				url: '/PostPage/post_add_buy/post_add_buy?postId=' + item.id
			})
		},
		del(item) {
			let that = this
			this.showCustomModal({
				content: '是否删除求租信息？',
				title: '',
				cancelText: '再想想',
				confirmText: '删除',
				cancelColor: 'rgba(0, 0, 0, 0.85)',
				confirmColor: '#666666',
				success(res){
					if(res.confirm){
						console.log('自定义弹窗点击了确认')
						Api.PostApi.del(item.id, (res) => {
							if (res.code == 200) {
								check_utils.showCustToast('删除成功')
								Api.PostApi.addPostBuyNumber(that, -1, item.id)
								that.records = that.records.filter(p => p.id != item.id)
								that.hideCustomModal()
							} else {
								check_utils.showCustToast(res.msg)
							}
						})
					}else{
						console.log('自定义弹窗点击了取消')
					}
				}
			})
			// uni.showModal({
			// 	title: '删除店铺',
			// 	content: '删除后，不可恢复哦～',
			// 	cancelColor: '#FF6430',
			// 	showCancel: true,
			// 	cancelText: '再想想',
			// 	confirmColor: '#666666',
			// 	confirmText: '确定',
			// 	success: function (res) {
			// 		if (res.confirm) {
			// 			console.log('点击了确定', res)
			// 			Api.PostApi.del(item.id, (res) => {
			// 				if (res.code == 200) {
			// 					check_utils.showCustToast('删除成功')
			// 					that.listDatas = that.listDatas.filter(p => p.id != item.id)
			// 				} else {
			// 					check_utils.showCustToast(res.msg)
			// 				}
			// 			})
			// 		} else if (res.cancel) {
			// 			console.log('用户取消注销');
			// 		}
			// 	}
			// })
		}
	},

}
</script>

<style scoped lang="scss">
@import url(../../static/css/base.css);

.post_list_my_manage_buy {
	min-height: 100vh;
	background-color: #F5F9FA;
	padding: 0 32rpx;

	.bh-round-btn {
		position: fixed;
		left: 0;
		bottom: 90rpx;
		right: 0;
		margin: auto;
	}

	.list {
		.li {
			margin-bottom: 32rpx;
			width: 686rpx;
			border-radius: 16rpx;
			background: #FFFFFF;
			padding: 40rpx;
			padding-bottom: 1rpx;
			box-sizing: border-box;
			position: relative;
			font-size: 28rpx;
			color: #000;

			>view {
				margin-bottom: 20rpx;
			}

			text {
				color: #999;
				font-size: 28rpx;
			}

			.mb0 {
				margin-bottom: 0;
			}

			.line {
				width: 100%;
				border-bottom: 1rpx #eee dashed;
			}

			.tag {
				width: 12rpx;
				height: 36rpx;
				border-radius: 4rpx;
				background: #F8D247;
				position: absolute;
				left: 0;
				top: 40rpx;
			}

			.cccline {
				height: 1rpx;
				border-top: 1rpx solid #eee;
				width: 582rpx;
				margin: 30rpx auto;
			}

			.operate {
				display: flex;

				>view {
					width: 50%;
					text-align: center;
					font-size: 24rpx;
					line-height: 40rpx;
					color: #666;

					&:first-child {
						border-right: 1rpx solid #eee;
					}
				}
			}
		}
	}
}
</style>